package com.lagou.edu.boss.rest.course;

import com.lagou.edu.common.entity.vo.Result;
import com.lagou.edu.course.api.CourseRemoteService;
import com.lagou.edu.course.api.dto.CourseDTO;
import com.lagou.edu.course.api.param.CourseQueryParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 课程Controller
 *
 * @author lm
 * @since 2021/10/29 14:16
 */
@Api(tags = "课程", produces = "application/json")
@Slf4j
@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private CourseRemoteService courseRemoteService;

    /**
     * 更新课程
     *
     * @param courseDTO 课程
     * @return 更新结果
     */
    @ApiOperation(value = "保存或者更新课程信息")
    @PostMapping(value = "/saveOrUpdateCourse")
    public Result saveOrUpdateCourse(@RequestBody CourseDTO courseDTO) {
        return Result.success(courseRemoteService.saveOrUpdateCourse(courseDTO));
    }

    @ApiOperation(value = "分页查询课程信息")
    @PostMapping("/getQueryCourses")
    public Result getQueryCourses(@RequestBody CourseQueryParam courseQueryParam)  {
        return Result.success(courseRemoteService.getQueryCourses(courseQueryParam));
    }

    @GetMapping("/getCourseById")
    public Result getCourseById(@RequestParam("courseId") Integer courseId, @RequestParam(required = false, name = "userId") Integer userId) {
        return Result.success(courseRemoteService.getCourseById(courseId, userId));
    }
}
